<template>
    <el-card class="box-card">
  <div slot="header" class="clearfix">
    <span>清宁体检APP医生端</span>
  </div>
  <p class="clearfix">
    
  </p>
  <el-form ref="form" :model="doctor" label-width="80px">
  <el-form-item label="账号">
    <el-input v-model="doctor.docCode"></el-input>
  </el-form-item>
  <el-form-item label="密码">
    <el-input v-model="doctor.password"></el-input>
  </el-form-item>
  
  
  <el-form-item>
    <el-button type="primary" @click="onSubmit()">登录</el-button>
    <el-button>忘记密码</el-button>
  </el-form-item>
</el-form>
</el-card>
</template>

<script>
import axios from 'axios';
import {useRouter,useRoute} from 'vue-router';
import {reactive,toRefs} from 'vue'
import { getSessionStorage,setSessionStorage } from '@/common'; 
export default {
  setup(){
    const router = useRouter();
    const route = useRoute();
    const state = reactive({
      doctor: {
          docCode: "",
          password: "",
        }
    });
    function onSubmit(){
        axios.post('/api/doctorLogin',state.doctor)
        .then(response=>{
            if(response.data.status==200){
              setSessionStorage("doctor",response.data.data);
              alert(response.data.data.realName+"登录成功");
              router.push('/orderlist');
            }
            else{
              alert(response.data.desc);
            }

        }).catch(error=>{
            console.log(error);
        })
    
  }
  return {
      ...toRefs(state),
      onSubmit
    }
}
}
</script>

<style scoped>
.text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
    margin:0 auto;
    margin-top:100px;
  }
  .clearfix{
    margin-bottom:20px;
  }
  
</style>